<?php
	/*列表分类*/
			function cate($pid=0,$a=array(),$leve=0){
			
		$sql="select * from `cate` where `pid`=$pid";
		$row = mysqli_query($GLOBALS['link'],$sql);
        	while ($arr=mysqli_fetch_assoc($row)) {
        		$str='';        		
        		for($i=0; $i<$leve; $i++){
        			$str.='√'; 
        		};  	
	        	
	        	$arr['news']=$str.$arr['news'];
	        	$a[]=$arr;
	        	$a=cate($arr['id'],$a,$leve+1);

			}
			return $a;
	     };

	/*分类编辑*/
			function caedit($rows,$cate=array()){

			$pid=$rows['pid'];

			$sql="select * from `cate` where `pid`='$pid'";

			$result=mysqli_query($GLOBALS['link'],$sql);

			while ($arr=mysqli_fetch_assoc($result)) {

			 	$cate[$rows['id']][]=$arr;

			
			}


			if ($pid!=0) {
				
				$sql="select * from `cate` where `id`='$pid'";

				$result=mysqli_query($GLOBALS['link'],$sql);

				$rows=mysqli_fetch_assoc($result);

				$cate=caedit($rows,$cate);
				 	
			 }
			 
				

			return $cate;
			}




		
	
	

?>